<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>意达设计</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/dealer.css"/>
</head>
<body class="body">

<!-- header -->
<div class="pageheader"><a href="javascript:void(0);" onclick="api.closeWin();" class="return"></a><span>编辑经销商</span></div>

<!-- contact -->
<div class="pad">
	<div class="biali"><span>经销商名称</span><input type="text" value="" name="addrname"></div>
	<div class="biali"><span>联系人</span><input type="text" value="" name="name"></div>
	<div class="biali"><span>联系人电话</span><input type="text" value="" name="phone"></div>
	<div class="biali"><span>联系地址</span><input type="text" value="" name="addr"></div>
	<div class="biali"><span>下单数量</span><input type="text" value="" name="num" disabled></div>
	<div class="biali"><span>下单金额</span><input type="text" value="￥" name="money" disabled></div>
	<div class="logBnt"><input type="button" value="保存" onclick="edituser()"></div>
</div>



</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/adaptive.js"></script>
<script type="text/javascript" src="../script/tabs.js"></script>
<script type="text/javascript">
    window['adaptive'].desinWidth = 750;
    window['adaptive'].baseFont = 28;
    window['adaptive'].maxWidth = 750;
    window['adaptive'].init();

    apiready = function () {
            $api.fixStatusBar($api.dom('.header'));
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err){
                api.closeWidget();
            });
            
            //api.showProgress();

            var para=api.pageParam;
           
            var p={token:token,id:para.id};
                api.ajax({
                    url: webSiteUrl+'/app/user/getuser',
                    method: 'post',
                    data: {
                        
                        values: p
                    }
                }, function(ret, err) {

                    if(ret.code==200){
                        $("input[name=addrname]").val(ret.data.addrname);
                        $("input[name=name]").val(ret.data.name);
                        $("input[name=phone]").val(ret.data.phone);
                        $("input[name=city]").val(ret.data.city);
                        $("input[name=addr]").val(ret.data.addr);
                        $("input[name=num]").val(ret.data.num);
                        $("input[name=money]").val(ret.data.money);
                     
                       
                    }else{alert(ret.msg)}
                });



                

            

        }

        function edituser(){
            var addrname=$("input[name=addrname]").val();
            var name=$("input[name=name]").val();
            var phone=$("input[name=phone]").val();
            var addr=$("input[name=addr]").val();

            if(addrname==''){
                api.alert({msg:"请输入备注姓名！"});return;
            }else if(name==''){
                api.alert({msg:"请输入姓名！"});return;
            }else if(phone==''){
                api.alert({msg:"请输入手机号！"});return;
            }else if( !/^1[34578]\d{9}$/.test(phone)){
                api.alert({msg:"手机号格式错误！"});return;
            }else if(addr==''){
                api.alert({msg:"请输入地址！"});return;
            }            

            var para=api.pageParam;
           
            var p={token:token,id:para.id,addrname:addrname,name:name,phone:phone,addr:addr};
                api.ajax({
                    url: webSiteUrl+'/app/user/edituser',
                    method: 'post',
                    data: {
                        
                        values: p
                    }
                }, function(ret, err) {

                    if(ret.code==200){

                        api.openWin({
                            name: 'dealer12Name',
                            url: './myuser.html',
                            reload: true,
                            pageParam: {
                                name: 'text'
                            }
                        });
                        
                      
                     
                       
                    }else{alert(JSON.stringify(ret.msg))}
                });


        }       
</script>

</html>
